package com.player;

import java.io.File;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class LocalhostFileListActivity extends ListActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Use an existing ListAdapter that will map an array
        // of strings to TextViews
        setListAdapter(new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, mStrings));
        getListView().setTextFilterEnabled(true);
    }
    
    private String[] getFileList() {
    	File mediaRoot = new File(this.mediaRoot);
    	if(!mediaRoot.exists()) mediaRoot.mkdirs();
    	return mediaRoot.list();
    }
    
    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
    	String mp3Path = "file://" + mediaRoot + "/" + mStrings[position];
    	Bundle myBundle = new Bundle();
    	myBundle.putString("path", mp3Path);
    	
    	Intent intent = new Intent(LocalhostFileListActivity.this, Mp3PlayerActivity.class);
    	intent.putExtras(myBundle);
    	Log.i("voaplayer", "！！！！！");
    	//Toast.makeText(this, "启动Mp3Activity", Toast.LENGTH_LONG).show();
    	startActivity(intent);
    }
    
//    private void testDialag() {
//        new AlertDialog.Builder(this)
//        .setTitle("对话框")
//        .setPositiveButton("确定", new DialogInterface.OnClickListener() {
//            public void onClick(DialogInterface dialog, int whichButton) {
//            	;
//            }
//        }).show();
//    }

    private String mediaRoot = "/sdcard/Samsung/Music/VOA";
    private String[] mStrings = getFileList();
}